const mysql = require('mysql')
const connParam = require('../config/connParam')

const pool = mysql.createPool(connParam)

const query = async (sql, value) => {
    return new Promise((resolve, reject) => {
        pool.getConnection(function (err, conn) {
            if (err) {
                reject(err)
            } else {
                conn.query(sql, value, (err, rows) => {
                    if (err) {
                        reject(err)
                    } else {
                        resolve(rows)
                    }
                    conn.release()
                })
            }
        })
    })
}

module.exports = {
    query
}